package com.fss.category1.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fss.common.annotation.Log;
import com.fss.common.core.controller.BaseController;
import com.fss.common.core.domain.AjaxResult;
import com.fss.common.enums.BusinessType;
import com.fss.category1.domain.Category1;
import com.fss.category1.service.ICategory1Service;
import com.fss.common.utils.poi.ExcelUtil;
import com.fss.common.core.page.TableDataInfo;

/**
 * 农产品品类Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/category1/category1")
public class Category1Controller extends BaseController
{
    @Autowired
    private ICategory1Service category1Service;

    /**
     * 查询农产品品类列表
     */
    @PreAuthorize("@ss.hasPermi('category1:category1:list')")
    @GetMapping("/list")
    public TableDataInfo list(Category1 category1)
    {
        startPage();
        List<Category1> list = category1Service.selectCategory1List(category1);
        return getDataTable(list);
    }

    /**
     * 导出农产品品类列表
     */
    @PreAuthorize("@ss.hasPermi('category1:category1:export')")
    @Log(title = "农产品品类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Category1 category1)
    {
        List<Category1> list = category1Service.selectCategory1List(category1);
        ExcelUtil<Category1> util = new ExcelUtil<Category1>(Category1.class);
        util.exportExcel(response, list, "农产品品类数据");
    }

    /**
     * 获取农产品品类详细信息
     */
    @PreAuthorize("@ss.hasPermi('category1:category1:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(category1Service.selectCategory1ByCategoryId(categoryId));
    }

    /**
     * 新增农产品品类
     */
    @PreAuthorize("@ss.hasPermi('category1:category1:add')")
    @Log(title = "农产品品类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Category1 category1)
    {
        return toAjax(category1Service.insertCategory1(category1));
    }

    /**
     * 修改农产品品类
     */
    @PreAuthorize("@ss.hasPermi('category1:category1:edit')")
    @Log(title = "农产品品类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Category1 category1)
    {
        return toAjax(category1Service.updateCategory1(category1));
    }

    /**
     * 删除农产品品类
     */
    @PreAuthorize("@ss.hasPermi('category1:category1:remove')")
    @Log(title = "农产品品类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(category1Service.deleteCategory1ByCategoryIds(categoryIds));
    }
}
